package com.sc.nft.admin.controller;

import cn.hutool.core.util.BooleanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.admin.request.AdminOperationLogRequest;
import com.sc.nft.admin.request.IdRequest;
import com.sc.nft.admin.request.UnbindCardAdminRqeust;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.dao.UserInfoDao;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.vo.AdminOperationLogVO;
import com.sc.nft.helper.SandAccountHelper;
import com.sc.nft.service.AdminOperationLogService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/operationLog")
@Api(tags="后台操作日志")
public class OperationLogController {
    private final AdminOperationLogService adminOperationLogService;
    private final SandAccountHelper sandAccountHelper;
    private final UserInfoDao userInfoDao;

    @PostMapping(value="/operationLogList", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "操作日志",notes="操作日志", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminOperationLogVO> operationLogList(@Valid @RequestBody AdminOperationLogRequest operationLogRequest){
       Page<AdminOperationLogVO>page= adminOperationLogService.operationLogList(operationLogRequest.getPageNo(),operationLogRequest.getPageSize(),
               operationLogRequest.getSysMemberName(),operationLogRequest.getStartDate(),operationLogRequest.getEndDate());
        return PageResult.success(page);
    }

    @ApiOperation(value = "查询银行卡", notes = "查询银行卡", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/queryBankCard", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<String> queryBankCard(@RequestBody IdRequest request) {
        return Result.success( sandAccountHelper.queryBindCard(userInfoDao.getById(request.getId())));
    }

    @ApiOperation(value = "解绑银行卡", notes = "解绑银行卡", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/discard", produces = MediaType.APPLICATION_JSON_VALUE)
    public Result discard(@RequestBody @Valid UnbindCardAdminRqeust request) {
        sandAccountHelper.unbindCardAdmin(request.getUserId(), request.getSandWithdrawUuid(),request.getRelatedCardNo());
        return Result.success();
    }
}
